package com.free.semantic.infrastruct.mapper;

import com.free.semantic.infrastruct.common.RelationItemDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RelationItemMapper {
    
    @Select("SELECT * FROM relation_item WHERE id = #{id}")
    RelationItemDO findById(@Param("id") Long id);
    
    @Select("SELECT * FROM relation_item WHERE semantic_network_id = #{semanticNetworkId}")
    List<RelationItemDO> findBySemanticNetworkId(@Param("semanticNetworkId") Long semanticNetworkId);
    
    @Select("SELECT * FROM relation_item WHERE target_object_id = #{targetObjectId}")
    List<RelationItemDO> findByTargetObjectId(@Param("targetObjectId") Long targetObjectId);
    
    @Insert("INSERT INTO relation_item(name, version, semantic_network_id, relation_str, create_time, update_time) " +
            "VALUES(#{name}, #{version}, #{semanticNetworkId}, #{relationStr}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(RelationItemDO relationItemDO);
    
    @Update("UPDATE relation_item SET name = #{name}, version = #{version}, " +
            "semantic_network_id = #{semanticNetworkId}, relation_str = #{relationStr}, " +
            "update_time = NOW() WHERE id = #{id}")
    int update(RelationItemDO relationItemDO);
    
    @Delete("DELETE FROM relation_item WHERE id = #{id}")
    int deleteById(@Param("id") Long id);
    
    @Delete("DELETE FROM relation_item WHERE semantic_network_id = #{semanticNetworkId}")
    int deleteBySemanticNetworkId(@Param("semanticNetworkId") Long semanticNetworkId);
    
    @Delete("DELETE FROM relation_item WHERE target_object_id = #{targetObjectId}")
    int deleteByTargetObjectId(@Param("targetObjectId") Long targetObjectId);
} 